package problem24;

import java.util.*;
//24.两两交换链表中的节点递归解法
//https://leetcode.cn/problems/swap-nodes-in-pairs/
//递归解法

class Solution2 {
    public ListNode swapPairs(ListNode head) {
        if(head == null || head.next == null) return head;
        ListNode newHead = head.next;
        ListNode next = newHead.next;
        newHead.next = head;
        head.next = swapPairs(next);
        return newHead;
    }
}